#ifndef FILEFILTER_H
#define FILEFILTER_H

#include <QObject>
#include <QDir>
#include <QMap>
#include <QFileInfo>
#include <mutex>
#include "mytypes.h"

namespace  Yzty{
    //文件筛选过滤器
    class FileFilter : public QObject
    {
            Q_OBJECT
        public:
            virtual ~FileFilter();

            static FileFilter* GetInstance(QObject *parent = nullptr);       //获取实例

            void Filter();  //过滤

            void SetFilterConditon(const Yzty::FileCheckCondition& constion);           //设置筛选条件

            const QMap<Yzty::FileTypeLimit::Type,QFileInfoList>& GetAllSelectAblePahts();   //获取所有类型的路径
            const QFileInfoList& GetSelectAblePaths(Yzty::FileTypeLimit::Type);             //根据不同类型获取可选路径
            WordLibCode GetWordLib();                                                   //获取选中的关键词库mask
            const Yzty::FileCheckCondition& GetFilterCondition();                       //获取筛选条件
            const QVector<QDir> Getdirpaths();                                                //获取检查路径
            int getAbsfilenumbers();
        signals:
            void FinishFilter();                                                        //完成过滤

        public slots:

        private:
            explicit FileFilter(QObject *parent = nullptr);
            static FileFilter* _instance;

            void TimeFilter();      //时间上过滤
            void PathFilter();      //路径上过滤
            void _pathfilter(const QDir& dir,QDir::Filters flag);

            void SizeFilter();      //大小上过滤
            void TypeFilter();      //类型上过滤

            void KeyWordFilter();   //关键词库上过滤

        private:
            Yzty::FileCheckCondition    _condition;                     //过滤条件
            QFileInfoList               _allfiles;
            QMap<Yzty::FileTypeLimit::Type,QFileInfoList>    _files;    //符合条件的路径
            WordLibCode                 _keywordlibs;                   //所包含的关键词

            std::atomic<int>             _filecnts;                      //"过滤前文件数"
            void Absfilenumbers();
            std::mutex _mutex;

    };
}

#endif // FILEFILTER_H
